package com.ruoyi.blindBoxManage.controller;

import com.ruoyi.blindBoxManage.domain.PlayType;
import com.ruoyi.blindBoxManage.service.IPlayTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 玩法类型Controller
 *
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/playType/playType")
public class PlayTypeController extends BaseController {
    @Autowired
    private IPlayTypeService playTypeService;

    /**
     * 查询玩法类型列表
     */
    @PreAuthorize("@ss.hasPermi('playType:playType:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlayType playType) {
        startPage();
        List<PlayType> list = playTypeService.selectPlayTypeList(playType);
        return getDataTable(list);
    }

    /**
     * 导出玩法类型列表
     */
    @PreAuthorize("@ss.hasPermi('playType:playType:export')")
    @Log(title = "玩法类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlayType playType) {
        List<PlayType> list = playTypeService.selectPlayTypeList(playType);
        ExcelUtil<PlayType> util = new ExcelUtil<PlayType>(PlayType.class);
        util.exportExcel(response, list, "玩法类型数据");
    }

    /**
     * 获取玩法类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('playType:playType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(playTypeService.selectPlayTypeById(id)) ;
    }

    /**
     * 新增玩法类型
     */
    @PreAuthorize("@ss.hasPermi('playType:playType:add')")
    @Log(title = "玩法类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlayType playType) {
        return toAjax(playTypeService.insertPlayType(playType));
    }

    /**
     * 修改玩法类型
     */
    @PreAuthorize("@ss.hasPermi('playType:playType:edit')")
    @Log(title = "玩法类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlayType playType) {
        return toAjax(playTypeService.updatePlayType(playType));
    }

    /**
     * 删除玩法类型
     */
    @PreAuthorize("@ss.hasPermi('playType:playType:remove')")
    @Log(title = "玩法类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(playTypeService.deletePlayTypeByIds(ids));
    }
}
